﻿using NHibernate.Mapping.ByCode;
using FinancePortal.Domain.Model;

namespace FinancePortal.Domain.Mapping
{
    public class ActivityScheduleMapping : EntityMapping<ActivitySchedule>
    {
        public ActivityScheduleMapping()
        {
            Property(x => x.FromDate, m => m.NotNullable(true));
            Property(x => x.ToDate, m => m.NotNullable(true));
            Property(x => x.RegisterDate, m => m.NotNullable(true));
            Property(x => x.Completed, m => m.NotNullable(true));

            ManyToOne<Activity>(x => x.Activity, m =>
            {
                m.Cascade(Cascade.None);
                m.NotNullable(true);
                m.Column("ActivityId");
                m.Insert(false);
                m.Update(false);
            });

            ManyToOne<Resource>(x => x.Owner, m =>
            {
                m.Cascade(Cascade.None);
                m.NotNullable(true);
                m.Column("Owner");
                m.Insert(false);
                m.Update(false);
            });

            Property(x => x.OwnerId, m =>
            {
                m.NotNullable(true);
                m.Column("Owner");
            });

            Property(x => x.WarningDays, m =>
                {
                    m.NotNullable(true);
                    m.Column("WarningDays");
                });

            Property(x => x.ActivityId, m =>
            {
                m.NotNullable(true);
                m.Column("ActivityId");
            });

            Bag(x => x.Participants, c =>
                {
                    c.Key(k =>
                        {
                            k.NotNullable(true);
                            k.Column("ActivityScheduleId");
                        });
                    c.Cascade(Cascade.None);
                    //c.Inverse(true);
                    c.Table("ActivityScheduleResource");
                }, r => r.ManyToMany(p => p.Column("ResourceId")));

            Bag(x => x.AreasClient, c =>
            {
                c.Key(k =>
                {
                    k.NotNullable(true);
                    k.Column("ActivityScheduleId");
                });
                c.Cascade(Cascade.None);
                //c.Inverse(true);
                c.Table("ActivityScheduleAreaClient");
            }, r => r.ManyToMany(p => p.Column("AreaId")));
        }
    }
}
